<%
String match_trace = "";

if(request.getAttribute("m_case") != null) {
	match_trace = ((Casemast) request.getAttribute("m_case")).getMerchant().getMatchTrace();
}

String nationality_opt = "<option value='MYS'>MALAYSIA</option>"
		   + "<option value='AUS'>AUSTRIALIA</option>"
		   + "<option value='BRN'>BRUNEI</option>"
		   + "<option value='KHM'>CAMBODIA</option>"
		   + "<option value='CHN'>CHINA</option>"
		   + "<option value='HKG'>HONG KONG</option>"
		   + "<option value='IND'>INDIA</option>"
		   + "<option value='IDN'>INDONESIA</option>"
		   + "<option value='JPN'>JAPAN</option>"
		   + "<option value='KOR'>KOREA</option>"
		   + "<option value='MMR'>MYANMAR</option>"
		   + "<option value='NZL'>NEW ZEALAND</option>"
		   + "<option value='PAK'>PAKISTAN</option>"
		   + "<option value='PHL'>PHILIPPINES</option>"
		   + "<option value='PRT'>PORTUGAL</option>"
		   + "<option value='SGP'>SINGAPORE</option>"
		   + "<option value='LKA'>SRI LANKA</option>"
		   + "<option value='TWN'>TAIWAN</option>"
		   + "<option value='THA'>THAILAND</option>"
		   + "<option value='GBR'>UNITED KINGDOM</option>"
		   + "<option value='USA'>UNITED STATE</option>"
		   + "<option value='VNM'>VIETNAM</option>"
		   + "<option value=''>OTHER</option>";
%>

<div class="row-fluid page">
	<div class="span12">

		<div class="section-header">MATCH / TRACE</div>
		<div class="form-horizontal merchant-main-content" style="overflow-y:auto; overflow-x:hidden">
			<div class="row-fluid">
				<div class="span12">
					<table class="tbl match_trace_tbl" style="width:98%">
						<thead>
							<tr>
								<th style="width:20%">First Name</th>
								<th style="width:20%">Last Name</th>
								<th style="width:20%">Owner IC/Passport</th>
								<th style="width:20%">Nationality</th>
								<th style="width:20%">Country Code</th>
							</tr>
						</thead>
						<tbody>
							<% 
								html = "";
							
								if(match_trace.length() > 0) {
									JSONArray arr = (JSONArray) JSONValue.parse(match_trace);
									for(int k = 0; k < arr.size(); k++) {
								    	String string = arr.get(k).toString();
								    	JSONObject obj = (JSONObject)JSONValue.parse(string);
		
								    	String f_name = (obj.get("f_name") == null) ? "" : obj.get("f_name").toString().trim();
								    	String l_name = (obj.get("l_name") == null) ? "" : obj.get("l_name").toString().trim();
								    	String ic = (obj.get("ic") == null) ? "" : obj.get("ic").toString().trim();
								    	String nationality = (obj.get("nationality") == null) ? "" : obj.get("nationality").toString().trim();
								    	String country_code = (obj.get("country_code") == null) ? "" : obj.get("country_code").toString().trim();
								    	
								    	html = "<tr data-index=" + k+1 + ">"
											+	"<td><input type='text' name='f_name' value='" + f_name + "' /></td>"
											+	"<td><input type='text' name='l_name' value='" + l_name + "' /></td>"
											+	"<td><input type='text' name='ic' value='" + ic + "' /></td>"
											+	"<td><select name='nationality'>" + nationality_opt + "</select></td>"
											+	"<td><input type='text' name='country_code' value='" + country_code + "' readonly='readonly' /></td>"
											+ "</tr>";
										
										
										html = html.replace("<option value='" + nationality + "'>", "<option value='" + nationality + "' selected>");
										
										out.println(html);
									}
								}
								else {
									html = "<tr data-index='1'>"
										+	"<td><input type='text' name='f_name' /></td>"
										+	"<td><input type='text' name='l_name' /></td>"
										+	"<td><input type='text' name='ic' /></td>"
										+	"<td><select name='nationality'>" + nationality_opt + "</select></td>"
										+	"<td><input type='text' name='country_code' readonly='readonly' value='MYS' /></td>"
										+ "</tr>";
										
									out.println(html);
								}
							
								
							%>
						
						</tbody>
					</table>
				</div>
			</div>
		</div>
		
	</div>
</div>